package top.hongthorn.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import top.hongthorn.pojo.RegionalEventOne;
import top.hongthorn.mapper.RegionalEventOneMapper;
import top.hongthorn.service.RegionalEventOneService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import top.hongthorn.util.Result;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 地区事件1 服务实现类
 * </p>
 *
 * @author 泓宇网络科技工作室
 * @since 2023-12-28 00:47:55
 */
@Service
@Transactional
public class RegionalEventOneServiceImpl extends ServiceImpl<RegionalEventOneMapper, RegionalEventOne> implements RegionalEventOneService {
    @Autowired
    private RegionalEventOneMapper regionalEventOneMapper;
    @Override
    public Result insert(RegionalEventOne one){
        if (regionalEventOneMapper.insert(one)>0){
            return Result.success(200,"添加成功");
        }
        return Result.error(500,"添加失败");
    }
    @Override
    public Result updateId(RegionalEventOne one){
        if (regionalEventOneMapper.updateById(one)!=0){
            return Result.success(200,"修改成功",1);
        }
        return Result.error(500,"修改失败",0);
    }
    @Override
    public Map selectPage(Integer startIndex, Integer pageIndex){
        Map<String, Object> map = new HashMap<>();
        Page<RegionalEventOne> selectPage = new Page(startIndex,pageIndex);
        IPage<RegionalEventOne> iPage = this.page(selectPage,null);
        map.put("code", 0);
        map.put("msg","true");
        map.put("count",iPage.getTotal());
        map.put("data",iPage.getRecords());
        return map;
    }
    @Override
    public Result deletById(Integer id){
        if (regionalEventOneMapper.deleteById(id) > 0){
            return Result.success(200,"删除成功");
        }
        return Result.error(500,"删除失败");
    }
}
